<?php

namespace App\Models\Api;
//
// +---------------------------------------------------------+
// | 开发组
// +---------------------------------------------------------+
// | Copyrigh  (c)  2020 The PHP Group
// +---------------------------------------------------------+
// | 后台用户表
// +---------------------------------------------------------+
// | zxc
// | php后端开发
// |
// +———————————————————+
//

use App\Tools\Financial;
use App\Tools\Prstatic;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Session;

class Express extends Model
{

    protected $table = 'express';
    protected $primaryKey = 'id';
    protected $dateFormat = 'U';// 时间戳
    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s'
    ];

    /**
     * 获取信息
     * @param $id
     */
    public static function getInfoById($id)
    {
        $info = self::where(['id' => $id])->first();
        if ($info) {
            $info['area_list'] = $info['area_list'] ? json_decode($info['area_list'], true) : [];
            return $info->toArray();
        }
        return [];
    }

    /**
     * 获取数据
     * @return mixed
     */
    public static function getAllList()
    {
        $list = self::where(['status' => 1])->select(['id', 'express_name', 'area_list', 'order_money'])->get();
        foreach ($list as $key => $item) {
            $list[$key]['area_list'] = $item['area_list'] ? json_decode($item['area_list'], true) : [];
        }
        return $list;
    }
}
